package com.shelpe.services.sustainer.autoDrive;

import org.springframework.batch.item.ItemProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shelpe.services.sustainer.client.AutoProductQueueClient;
import com.shelpe.services.sustainer.entity.jpa.Adgroup;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class ExecuteMobileQscoreProcessor implements ItemProcessor<Adgroup, AdjustAdgroupResult> {

	@Autowired
	private AutoProductQueueClient autoProductQueueClient;
	
	@Override
	public AdjustAdgroupResult process(Adgroup adgroup) throws Exception {
		log.debug("ExecuteMobileQscore[{}]: {}", adgroup.getAdgroupID(), adgroup);
		AdjustAdgroupResult res = new AdjustAdgroupResult();
		res.setAdgroup(adgroup);
		if("online".equals(adgroup.getOnlineStatus())){
			AutoProductQueueClient.ExecutionRes dto = this.autoProductQueueClient.executeMobileQscore(adgroup.getUserID(), adgroup.getAdgroupID());
			if(!dto.isSuccess()){
				log.error("fail to execute mobile qscore: {}", adgroup);
			}
			res.setStatus(dto.isSuccess()?1:-1);
		}
		
		return res;
	}

}
